//
//  HWVIPProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/8/29.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWVIPProtocol: NSObject {
    var model:HWNewVIPModel?
    var clickItem:((_:String)->())?
    var goToCenterClick:(()->())?
}
extension HWVIPProtocol: UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        
        return 2
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let topCell = HWVIPTopCell.cellWithTableView(tableView: tableView)
        let vipPrivilegeCell = HWVIPPrivilegeCell.cellWithTableView(tableView: tableView)
        if indexPath.section == 0 {
            topCell.model = model
            topCell.clickItem = {
                self.clickItem?($0)
            }
            topCell.goToCenterClick = {
                self.goToCenterClick?()
            }
            return topCell
        }
        vipPrivilegeCell.model = model
        return vipPrivilegeCell
    }
    
//    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
//        if indexPath.section == 1 {
//            if (cell.responds(to: #selector(getter: UIView.tintColor))){
//                let cornerRadius: CGFloat = 14*widthScale
//                cell.backgroundColor = .clear
//                let layer: CAShapeLayer = CAShapeLayer()
//                let path: CGMutablePath = CGMutablePath()
//
//                cell.updateConstraints()
//                let bounds: CGRect = cell.bounds
//                bounds.insetBy(dx: 25, dy: 0)
//                var addLine: Bool = false
//
//                if indexPath.row == 0 && indexPath.row == ( tableView.numberOfRows(inSection: indexPath.section) - 1) {
//                    path.addRoundedRect(in: bounds, cornerWidth: cornerRadius, cornerHeight: cornerRadius)
//
//                } else if indexPath.row == 0 {
//                    path.move(to: CGPoint(x: bounds.minX, y: bounds.maxY))
//                    path.addArc(tangent1End: CGPoint(x: bounds.minX, y: bounds.minY), tangent2End: CGPoint(x: bounds.midX, y: bounds.minY), radius: cornerRadius)
//                    path.addArc(tangent1End: CGPoint(x: bounds.maxX, y: bounds.minY), tangent2End: CGPoint(x: bounds.maxX, y: bounds.midY), radius: cornerRadius)
//                    path.addLine(to: CGPoint(x: bounds.maxX, y: bounds.maxY))
//
//                } else if indexPath.row == (tableView.numberOfRows(inSection: indexPath.section) - 1) {
//                    path.move(to: CGPoint(x: bounds.minX, y: bounds.minY))
//                    path.addArc(tangent1End: CGPoint(x: bounds.minX, y: bounds.maxY), tangent2End: CGPoint(x: bounds.midX, y: bounds.maxY), radius: cornerRadius)
//                    path.addArc(tangent1End: CGPoint(x: bounds.maxX, y: bounds.maxY), tangent2End: CGPoint(x: bounds.maxX, y: bounds.midY), radius: cornerRadius)
//                    path.addLine(to: CGPoint(x: bounds.maxX, y: bounds.minY))
//
//                } else {
//                    path.addRect(bounds)
//                    addLine = true
//                }
//
//                layer.path = path
//                layer.fillColor = UIColor.colorWithHexString(hexString: "#272727").cgColor
//
//
//                //            if addLine {
//                //                let lineLayer: CALayer = CALayer()
//                //                let lineHeight: CGFloat = 1.0 / UIScreen.main.scale
//                //                lineLayer.frame = CGRect(x: bounds.minX + 10.0, y: bounds.size.height - lineHeight, width: bounds.size.width, height: lineHeight)
//                //                lineLayer.backgroundColor = tableView.separatorColor?.cgColor
//                //                layer.addSublayer(lineLayer)
//                //            }
//
//                let testView: UIView = UIView(frame: bounds)
//                testView.layer.insertSublayer(layer, at: 0)
//                testView.backgroundColor = .clear
//                testView.layer.borderWidth = 1
//                testView.layer.borderColor = UIColor.red.cgColor
//                cell.backgroundView = testView
//                //            }
//            }
//        }
//
//    }

    
}

